<template>
  <div class="supplierOrder4Deliver" style="padding-bottom: 50px">
    <el-row type="flex" justify="center">
      <div class="input_box">
        <el-input
            v-model="selectInput"
            placeholder="请输入查询内容"
            size="small"
            clearable
        >
          <template #append>
            <el-button @click="search(selectInput)" size="small">
              <el-icon>
                <Search/>
              </el-icon>
            </el-button>
          </template>
        </el-input>
      </div>
      <el-card>
        <el-table
            :data="orderData"
            class-name="orderTable"
            :header-cell-style="{
              'text-align':'center',
              'font-size':'19px',
              'font-weight':'normal',
              'border-color':'black'
            }"
            :cell-style="{
              'text-align':'center',
              'height':'30px',
              'font-size':'16px',
              'background-color':'#b8e3df',
              'border-color':'black'
            }"
            border
        >
          <el-table-column type="expand" label="订单详情" width="130px">
            <template #default="orderDetails">
              <div class="table">
                <h5>&nbsp;Details</h5>
                <el-table
                    :data="orderDetails.row.orderItemList"
                    class-name="orderItemsTable"
                    :header-cell-style="{
                    'font-size':'17px',
                    'font-weight':'normal',
                  }"
                    :cell-style="{
                    'font-size':'16px',
                  }"
                    :row-class-name="tableRowClassName"
                    style="width: 75%"
                >
                  <el-table-column prop="goodsImg" label="商品图片">
                    <template v-slot="scope">
                      <img :src="scope.row.goodsImg" min-width="70px" height="80px"/>
                    </template>
                  </el-table-column>
                  <el-table-column prop="goodsName" label="商品名称"/>
                  <el-table-column prop="goodsCount" label="数量">
                    <template v-slot="scope">
                      <el-tag size="small" type="success" effect="light">
                        {{scope.row.goodsCount}}
                      </el-tag>
                    </template>
                  </el-table-column>
                  <el-table-column prop="goodsUnitPrice" label="单价"/>
                </el-table>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="orderTime" label="下单时间" width="180px" :formatter="formatter"/>
          <el-table-column prop="purchaserNickname" label="采购商" width="150px"/>
          <el-table-column prop="purchaserAccount" label="联系方式" width="180px"/>
          <el-table-column prop="purchaserAddress" label="地址" width="250px"/>
          <el-table-column prop="realPayment" label="实付款" width="130px"/>
          <el-table-column prop="orderState" label="状态" width="120px" fixed="right">
            <template v-slot="scope">
              <span v-if="judgeStatus(scope.row.orderState) == true">
                <el-tag size="small" style="font-size: 13px" type="success" effect="light">
                  已完成
                </el-tag>
              </span>
              <span v-if="judgeStatus(scope.row.orderState) == false">
                <el-tag size="small" style="font-size: 13px" type="danger" effect="light">
                  取消交易
                </el-tag>
              </span>
            </template>
          </el-table-column>
        </el-table>
      </el-card>
    </el-row>
  </div>
</template>

<script setup name="PurchaserOrder">
import {Search} from "@element-plus/icons-vue";
import {ref, reactive, onMounted} from "vue";
import request from "@/utils/request";

const orderData = reactive([])

const selectInput = ref('')

onMounted(() => {
  selectAllCompletedOrder()
})

function judgeStatus(state) {
  return state == '2'
}

function tableRowClassName({rowIndex}) {
  if (rowIndex % 2 == 0) {
    return ""
  }
  return "warning-row"
}

function selectAllCompletedOrder() {
  let params = {
    selectInput: selectInput.value ? selectInput.value : null
  }
  request.get("/t-order/getSupplierCompletedOrder", {
    params: params
  }).then((resp) => {
    console.log(resp.data)
    orderData.length = 0
    orderData.push(...resp.data)
  })
}

function search() {
  selectAllCompletedOrder()
}

function formatter(row, column) {
  let newTime = row.orderTime.replace("T", " ")
  return newTime
}
</script>

<style scoped>
.el-card {
  margin-top: 6px;
  width: 580px;
  align: center;
  background-color: #b8e3df;
}

.input_box {
  width: 300px;
  border-radius: 95px;
  background: lightpink;
  margin-top: 6px;
}

:deep(.el-input__wrapper) {
  background-color: transparent;
  border-radius: 95px;
  border: 0px;
  box-shadow: 0 0 0 0px;
  font-size: 11px;
}

:deep(.el-input-group__append) {
  background: lightpink;
  border-radius: 95px;
  border: 0px;
  box-shadow: 0 0 0 0px;
}

.orderItemsTable {
  padding: 10px;
}

/*
:deep(.el-table__row.warning-row) {
  background: #d1e9f4;
}
*/

.orderTable {
  border: 1px solid black;
}
</style>
